#ifdef _WIN32
#define getc_unlocked(stdin) getc(stdin)
#endif
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <list>
#include <bitset>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <ctime>
#include <numeric>
#include <functional>
#include <valarray>
#include <complex>
using namespace std;

const int dx[]={0,-1,0,1,-1,1, 1,-1};
const int dy[]={1,0,-1,0, 1,1,-1,-1};
const double eps=1e-8;

typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vgraph;
typedef vector<pii> vpii;
typedef vector<LL> vLL;
typedef vector<string> vs;

#define sz(a) a.size()
#define fori(i,a,b) for(int i(a),_b(b);i<=_b;++i)
#define ford(i,a,b) for(int i(a),_b(b);i>=_b;--i)
#define forn(i,n) fori(i,0,n-1)
#define fora(i,a) forn(i,sz(a))
#define fore(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define clear0(a) memset(a,0,sizeof(a))
#define clearm1(a) memset(a,-1,sizeof(a))
#define maximum(a) (*max_element(all(a)))
#define minimum(a) (*min_element(all(a)))
#define findx(a,x) (find(all(a),x)-a.begin())
#define two(X) (1LL<<(X))
#define contain(S,X) ((S)&two(X))
#define setbit(S,X) ((S)|=two(X))
#define clearbit(S,X) ((S)&=~two(X))
#define togglebit(S,X) ((S)^=two(X))
#define sqr(a) ((a)*(a))
#define fin "input.inp"
#define fout "output.out"
#define nmax 50
#define mmax 100
#define kmax 10
#define modulo 1000000007
#define maxc 999999999
#define fi first
#define se second

class RectangleArea {
bool fr[nmax][nmax];
int n,m;
void dfs(int x,int y,vs known)
{
	fr[x][y]=false;
	vi row,col;
	forn(i,n) if (i!=x && known[i][y]=='Y') row.pb(i);
	forn(i,m) if (i!=y && known[x][i]=='Y') col.pb(i);
	
	fora(i,row)
	fora(j,col)
	if (fr[row[i]][col[j]] && known[row[i]][col[j]]=='N')
	{
		known[row[i]][col[j]]='Y';
		dfs(row[i],col[j],known);
	}
}
void bfs(int x,int y,vs known)
{
	vpii q;
	q.pb(mp(x,y));
	int r=0;
	fr[x][y]=false;
	while (r<sz(q))
	{
		pii u=q[r++];
		forn(i,n) if (fr[i][u.se] && known[i][u.se]=='Y') q.pb(mp(i,u.se)),fr[i][u.se]=false;
		forn(i,m) if (fr[u.fi][i] && known[u.fi][i]=='Y') q.pb(mp(u.fi,i)),fr[u.fi][i]=false;
	}
}

public:
	int minimumQueries(vector <string> known) {
		n=sz(known); m=sz(known[0]);
		int area=0,freerow=0,freecol=0;
		bool frrow[nmax],frcol[nmax];
		
		forn(i,n) forn(j,m) fr[i][j]=true;
		forn(i,n)
		forn(j,m)
		if (fr[i][j] && known[i][j]=='Y') dfs(i,j,known);
		
		forn(i,n) forn(j,m) fr[i][j]=true;
		forn(i,n)
		forn(j,m)
		if (fr[i][j] && known[i][j]=='Y') 
		{
			bfs(i,j,known);
			area++;
		}
		
		forn(i,n) frrow[i]=true; 
		forn(i,m) frcol[i]=true;
		forn(i,n)
		forn(j,m)
		if (known[i][j]=='Y') frrow[i]=frcol[j]=false;
		forn(i,n) if (frrow[i]) freerow++; 
		forn(i,m) if (frcol[i]) freecol++;
		
		return area-1+freerow+freecol;
	}
};


// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit-pf 2.3.0
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <cmath>
using namespace std;
bool KawigiEdit_RunTest(int testNum, vector <string> p0, bool hasAnswer, int p1) {
	cout << "Test " << testNum << ": [" << "{";
	for (int i = 0; int(p0.size()) > i; ++i) {
		if (i > 0) {
			cout << ",";
		}
		cout << "\"" << p0[i] << "\"";
	}
	cout << "}";
	cout << "]" << endl;
	RectangleArea *obj;
	int answer;
	obj = new RectangleArea();
	clock_t startTime = clock();
	answer = obj->minimumQueries(p0);
	clock_t endTime = clock();
	delete obj;
	bool res;
	res = true;
	cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
	if (hasAnswer) {
		cout << "Desired answer:" << endl;
		cout << "\t" << p1 << endl;
	}
	cout << "Your answer:" << endl;
	cout << "\t" << answer << endl;
	if (hasAnswer) {
		res = answer == p1;
	}
	if (!res) {
		cout << "DOESN'T MATCH!!!!" << endl;
	} else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
		cout << "FAIL the timeout" << endl;
		res = false;
	} else if (hasAnswer) {
		cout << "Match :-)" << endl;
	} else {
		cout << "OK, but is it right?" << endl;
	}
	cout << "" << endl;
	return res;
}
int main() {
	bool all_right;
	bool disabled;
	bool tests_disabled;
	all_right = true;
	tests_disabled = false;
	
	vector <string> p0;
	int p1;
	
	{
	// ----- test 0 -----
	disabled = false;
	string t0[] = {"NN","NN"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 3;
	all_right = (disabled || KawigiEdit_RunTest(0, p0, true, p1) ) && all_right;
	tests_disabled = tests_disabled || disabled;
	// ------------------
	}
	
	{
	// ----- test 1 -----
	disabled = false;
	string t0[] = {"YNY","NYN","YNY"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 1;
	all_right = (disabled || KawigiEdit_RunTest(1, p0, true, p1) ) && all_right;
	tests_disabled = tests_disabled || disabled;
	// ------------------
	}
	
	{
	// ----- test 2 -----
	disabled = false;
	string t0[] = {"YY","YY","YY","YY"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 0;
	all_right = (disabled || KawigiEdit_RunTest(2, p0, true, p1) ) && all_right;
	tests_disabled = tests_disabled || disabled;
	// ------------------
	}
	
	{
	// ----- test 3 -----
	disabled = false;
	string t0[] = {"NNNNNNNNNN"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 10;
	all_right = (disabled || KawigiEdit_RunTest(3, p0, true, p1) ) && all_right;
	tests_disabled = tests_disabled || disabled;
	// ------------------
	}
	
	{
	// ----- test 4 -----
	disabled = false;
	string t0[] = {"NNYYYNN","NNNNNYN","YYNNNNY","NNNYNNN","YYNNNNY"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 2;
	all_right = (disabled || KawigiEdit_RunTest(4, p0, true, p1) ) && all_right;
	tests_disabled = tests_disabled || disabled;
	// ------------------
	}
	
	if (all_right) {
		if (tests_disabled) {
			cout << "You're a stud (but some test cases were disabled)!" << endl;
		} else {
			cout << "You're a stud (at least on given cases)!" << endl;
		}
	} else {
		cout << "Some of the test cases had errors." << endl;
	}
	return 0;
}
// END KAWIGIEDIT TESTING
//Powered by KawigiEdit-pf 2.3.0!
